home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / old / iff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  6.1 KB  |  262 lines

  1. /* $Id: iff.c,v 1.1 1993/03/15 21:30:53 mjl Exp $
  2.    $Log: iff.c,v $
  3.  * Revision 1.1  1993/03/15  21:30:53  mjl
  4.  * Files shuffled around in the Amiga driver reorganization.
  5.  *
  6.  * Revision 1.2  1992/10/12  17:11:22  mjl
  7.  * Amiga-specific mods, including ANSI-fication.
  8.  *
  9.  * Revision 1.1  1992/05/20  21:35:25  furnish
  10.  * Initial checkin of the whole PLPLOT project.
  11.  *
  12. */
  13.  
  14. /*    iff.c
  15.  
  16.     PLPLOT Amiga IFF device driver.
  17.     Originally written by Tomas Rokicki (Radical Eye Software).
  18. */
  19.  
  20. #include "plplot.h"
  21. #include <stdio.h>
  22. #include "dispatch.h"
  23. #include "plamiga.h"
  24.  
  25. /* top level declarations */
  26.  
  27. static PLINT xsubw, ysubw;
  28. static PLINT vxwidth, vywidth;
  29.  
  30. /* (dev) will get passed in eventually, so this looks weird right now */
  31.  
  32. static PLDev device;
  33. static PLDev (*dev) = &device;
  34.  
  35. /*----------------------------------------------------------------------*\
  36. * iff_init()
  37. *
  38. * Initialize device.
  39. \*----------------------------------------------------------------------*/
  40.  
  41. void 
  42. iff_init(PLStream *pls)
  43. {
  44.     pls->termin = 0;        /* not an interactive terminal */
  45.     pls->icol = 1;
  46.     pls->width = 1;
  47.     pls->bytecnt = 0;
  48.     pls->page = 0;
  49.  
  50.     if (!pls->pageset) {
  51.     pls->xdpi    = plGetFlt("Enter desired horizontal resolution (dpi): ");
  52.     pls->ydpi    = plGetFlt("Enter desired vertical   resolution (dpi): ");
  53.     pls->xlength = plGetInt("Enter desired horizontal size in pixels  : ");
  54.     pls->ylength = plGetInt("Enter desired vertical   size in pixels  : ");
  55.     pls->pageset = 1;
  56.     }
  57.  
  58.     vxwidth = pls->xlength * 25;
  59.     vywidth = pls->ylength * 25;
  60.  
  61.     dev->xold = UNDEFINED;
  62.     dev->yold = UNDEFINED;
  63.     dev->xmin = 0;
  64.     dev->xmax = pls->xlength;
  65.     dev->ymin = 0;
  66.     dev->ymax = pls->ylength;
  67.  
  68.     if (!pls->orient) {
  69.     setpxl((PLFLT) (pls->xdpi * 25. / 25.4), (PLFLT) (pls->ydpi * 25 / 25.4));
  70.     setphy(0, vxwidth, 0, vywidth);
  71.     }
  72.     else {
  73.     setpxl((PLFLT) (pls->ydpi * 25 / 25.4), (PLFLT) (pls->xdpi * 25 / 25.4));
  74.     setphy(0, vywidth, 0, vxwidth);
  75.     }
  76.  
  77.     xsubw = pls->xlength - 2;
  78.     ysubw = pls->ylength - 2;
  79.  
  80.     /* Allocate bitmap and initialize for line drawing */
  81.     if (mapinit(pls->xlength, pls->ylength)) {
  82.     plexit("");
  83.     }
  84. }
  85.  
  86. /*----------------------------------------------------------------------*\
  87. * iff_line()
  88. *
  89. * Draw a line in the current color from (x1,y1) to (x2,y2).
  90. \*----------------------------------------------------------------------*/
  91.  
  92. void 
  93. iff_line(PLStream *pls, PLSHORT x1a, PLSHORT y1a, PLSHORT x2a, PLSHORT y2a)
  94. {
  95.     int x1=x1a, y1=y1a, x2=x2a, y2=y2a;
  96.     long xn1, yn1, xn2, yn2;
  97.  
  98.     if (!pls->orient) {
  99.     xn1 = (x1 * xsubw) / vxwidth;
  100.     yn1 = (y1 * ysubw) / vywidth;
  101.     xn2 = (x2 * xsubw) / vxwidth;
  102.     yn2 = (y2 * ysubw) / vywidth;
  103.     switch (pls->width) {
  104.     case 3:
  105.         mapline(xn1, ysubw - yn1, xn2, ysubw - yn2);
  106.     case 2:
  107.         mapline(xn1 + 2, ysubw - yn1 + 2, xn2 + 2, ysubw - yn2 + 2);
  108.     case 1:
  109.     default:
  110.         mapline(xn1 + 1, ysubw - yn1 + 1, xn2 + 1, ysubw - yn2 + 1);
  111.     }
  112.     }
  113.     else {
  114.     xn1 = (x1 * ysubw) / vywidth;
  115.     yn1 = (y1 * xsubw) / vxwidth;
  116.     xn2 = (x2 * ysubw) / vywidth;
  117.     yn2 = (y2 * xsubw) / vxwidth;
  118.     switch (pls->width) {
  119.     case 3:
  120.         mapline(yn1, xn1, yn2, xn2);
  121.     case 2:
  122.         mapline(yn1 + 2, xn1 + 2, yn2 + 2, xn2 + 2);
  123.     case 1:
  124.     default:
  125.         mapline(yn1 + 1, xn1 + 1, yn2 + 1, xn2 + 1);
  126.     }
  127.     }
  128. }
  129.  
  130. /*----------------------------------------------------------------------*\
  131. * iff_polyline()
  132. *
  133. * Draw a polyline in the current color.
  134. \*----------------------------------------------------------------------*/
  135.  
  136. void 
  137. iff_polyline (PLStream *pls, PLSHORT *xa, PLSHORT *ya, PLINT npts)
  138. {
  139.     PLINT i;
  140.  
  141.     for (i=0; i<npts-1; i++) 
  142.       iff_line( pls, xa[i], ya[i], xa[i+1], ya[i+1] );
  143. }
  144.  
  145. /*----------------------------------------------------------------------*\
  146. * iff_clear()
  147. *
  148. * Clear page. 
  149. * Here need to close file since only 1 page/file is allowed (for now).
  150. \*----------------------------------------------------------------------*/
  151.  
  152. void 
  153. iff_clear(PLStream *pls)
  154. {
  155.     iffwritefile((PLINT) pls->xdpi, (PLINT) pls->ydpi, pls->OutFile);
  156.     fclose(pls->OutFile);
  157. }
  158.  
  159. /*----------------------------------------------------------------------*\
  160. * iff_page()
  161. *
  162. * Set up for the next page.  
  163. * Advance to next family file if necessary (file output).
  164. * Here need to open a new file since only 1 page/file is allowed (for now).
  165. \*----------------------------------------------------------------------*/
  166.  
  167. void 
  168. iff_page(PLStream *pls)
  169. {
  170.     pls->page++;
  171.     mapclear();
  172.     plOpenFile(pls);
  173. }
  174.  
  175. /*----------------------------------------------------------------------*\
  176. * iff_adv()
  177. *
  178. * Advance to the next page.
  179. \*----------------------------------------------------------------------*/
  180.  
  181. void 
  182. iff_adv(PLStream *pls)
  183. {
  184.     iff_clear(pls);
  185.     iff_page(pls);
  186. }
  187.  
  188. /*----------------------------------------------------------------------*\
  189. * iff_tidy()
  190. *
  191. * Close graphics file or otherwise clean up.
  192. \*----------------------------------------------------------------------*/
  193.  
  194. void 
  195. iff_tidy(PLStream *pls)
  196. {
  197.     iff_clear(pls);
  198.     mapfree();
  199.     pls->fileset = 0;
  200.     pls->page = 0;
  201.     pls->OutFile = NULL;
  202. }
  203.  
  204. /*----------------------------------------------------------------------*\
  205. * iff_color()
  206. *
  207. * Set pen color.
  208. \*----------------------------------------------------------------------*/
  209.  
  210. void 
  211. iff_color(PLStream *pls)
  212. {
  213. }
  214.  
  215. /*----------------------------------------------------------------------*\
  216. * iff_text()
  217. *
  218. * Switch to text mode.
  219. \*----------------------------------------------------------------------*/
  220.  
  221. void 
  222. iff_text(PLStream *pls)
  223. {
  224. }
  225.  
  226. /*----------------------------------------------------------------------*\
  227. * iff_graph()
  228. *
  229. * Switch to graphics mode.
  230. \*----------------------------------------------------------------------*/
  231.  
  232. void 
  233. iff_graph(PLStream *pls)
  234. {
  235. }
  236.  
  237. /*----------------------------------------------------------------------*\
  238. * iff_width()
  239. *
  240. * Set pen width.
  241. \*----------------------------------------------------------------------*/
  242.  
  243. void 
  244. iff_width(PLStream *pls)
  245. {
  246.     if (pls->width < 1)
  247.     pls->width = 1;
  248.     else if (pls->width > 3)
  249.     pls->width = 3;
  250. }
  251.  
  252. /*----------------------------------------------------------------------*\
  253. * iff_esc()
  254. *
  255. * Escape function.
  256. \*----------------------------------------------------------------------*/
  257.  
  258. void 
  259. iff_esc(PLStream *pls, PLINT op, char *ptr)
  260. {
  261. }
  262.